﻿namespace OboutInc.Show
{
    using System;
    using System.ComponentModel;
    using System.Runtime.Serialization;
    using System.Web.UI;
    using System.Xml;

    [Serializable, ToolboxItem(false), TypeConverter(typeof(ExpandableObjectConverter))]
    public class Changer : Control, INamingContainer, ISerializable
    {
        public Changer()
        {
        }

        protected Changer(SerializationInfo info, StreamingContext context)
        {
        }

        public void Deserialize(XmlElement parentNode)
        {
            this.Type = (ChangerType) Enum.Parse(typeof(ChangerType), parentNode.GetAttribute("Type"));
            this.ArrowType = (OboutInc.Show.ArrowType) Enum.Parse(typeof(OboutInc.Show.ArrowType), parentNode.GetAttribute("ArrowType"));
            this.Position = (ChangerPosition) Enum.Parse(typeof(ChangerPosition), parentNode.GetAttribute("Position"));
            this.VerticalAlign = (ChangerVerticalAlign) Enum.Parse(typeof(ChangerVerticalAlign), parentNode.GetAttribute("VerticalAlign"));
            this.HorizontalAlign = (ChangerHorizontalAlign) Enum.Parse(typeof(ChangerHorizontalAlign), parentNode.GetAttribute("HorizontalAlign"));
            this.Width = int.Parse(parentNode.GetAttribute("Width"));
            this.Height = int.Parse(parentNode.GetAttribute("Height"));
        }

        public void Serialize(ref XmlElement parentNode)
        {
            parentNode.SetAttribute("Type", this.Type.ToString());
            parentNode.SetAttribute("ArrowType", this.ArrowType.ToString());
            parentNode.SetAttribute("Position", this.Position.ToString());
            parentNode.SetAttribute("VerticalAlign", this.VerticalAlign.ToString());
            parentNode.SetAttribute("HorizontalAlign", this.HorizontalAlign.ToString());
            parentNode.SetAttribute("Width", this.Width.ToString());
            parentNode.SetAttribute("Height", this.Height.ToString());
        }

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
        }

        [Bindable(true), Description("If true, changer can be positioned at absolute position using css."), Category("Show appearance"), DefaultValue(false)]
        public bool AllowAbsolutePosition
        {
            get
            {
                if (this.ViewState["AllowAbsolutePosition"] == null)
                {
                    this.ViewState["AllowAbsolutePosition"] = false;
                }
                return bool.Parse(this.ViewState["AllowAbsolutePosition"].ToString());
            }
            set
            {
                this.ViewState["AllowAbsolutePosition"] = value;
            }
        }

        [Description("position of the arrows reported to the numbers"), Category("Show Changer Appearance"), DefaultValue("ArrowType.Side1"), Bindable(true)]
        public OboutInc.Show.ArrowType ArrowType
        {
            get
            {
                if (this.ViewState["ArrowType"] == null)
                {
                    this.ViewState["ArrowType"] = OboutInc.Show.ArrowType.Side1;
                }
                return (OboutInc.Show.ArrowType) this.ViewState["ArrowType"];
            }
            set
            {
                this.ViewState["ArrowType"] = value;
            }
        }

        [Bindable(true), Description("height of the show panels changer"), Category("Show appearance"), DefaultValue(50)]
        public int Height
        {
            get
            {
                if (this.ViewState["ChangerHeight"] == null)
                {
                    this.ViewState["ChangerHeight"] = 50;
                }
                return (int) this.ViewState["ChangerHeight"];
            }
            set
            {
                this.ViewState["ChangerHeight"] = value;
            }
        }

        [Bindable(true), Description("horizontal aligning of the changer content"), Category("Show Changer Appearance"), DefaultValue("ChangerHorizontalAlign.Center")]
        public ChangerHorizontalAlign HorizontalAlign
        {
            get
            {
                if (this.ViewState["HorizontalAlign"] == null)
                {
                    this.ViewState["HorizontalAlign"] = ChangerHorizontalAlign.Center;
                }
                return (ChangerHorizontalAlign) this.ViewState["HorizontalAlign"];
            }
            set
            {
                this.ViewState["HorizontalAlign"] = value;
            }
        }

        [DefaultValue(""), Description("Title of the MoveLeft image."), Category("Show appearance"), Bindable(true)]
        public string MoveLeftTitle
        {
            get
            {
                if (this.ViewState["MoveLeftTitle"] == null)
                {
                    this.ViewState["MoveLeftTitle"] = "";
                }
                return (string) this.ViewState["MoveLeftTitle"];
            }
            set
            {
                this.ViewState["MoveLeftTitle"] = value;
            }
        }

        [DefaultValue(""), Description("Title of the MoveRight image."), Category("Show appearance"), Bindable(true)]
        public string MoveRightTitle
        {
            get
            {
                if (this.ViewState["MoveRightTitle"] == null)
                {
                    this.ViewState["MoveRightTitle"] = "";
                }
                return (string) this.ViewState["MoveRightTitle"];
            }
            set
            {
                this.ViewState["MoveRightTitle"] = value;
            }
        }

        [Bindable(true), Category("Show appearance"), DefaultValue(""), Description("Title of the Pause image.")]
        public string PauseTitle
        {
            get
            {
                if (this.ViewState["PauseTitle"] == null)
                {
                    this.ViewState["PauseTitle"] = "";
                }
                return (string) this.ViewState["PauseTitle"];
            }
            set
            {
                this.ViewState["PauseTitle"] = value;
            }
        }

        [Description("position of the panels changer"), Bindable(true), Category("Show Changer Appearance"), DefaultValue("ChangerPosition.Bottom")]
        public ChangerPosition Position
        {
            get
            {
                if (this.ViewState["ChangerPosition"] == null)
                {
                    this.ViewState["ChangerPosition"] = ChangerPosition.Bottom;
                }
                return (ChangerPosition) this.ViewState["ChangerPosition"];
            }
            set
            {
                this.ViewState["ChangerPosition"] = value;
            }
        }

        [Bindable(true), Description("Title of the Start image."), Category("Show appearance"), DefaultValue("")]
        public string StartTitle
        {
            get
            {
                if (this.ViewState["StartTitle"] == null)
                {
                    this.ViewState["StartTitle"] = "";
                }
                return (string) this.ViewState["StartTitle"];
            }
            set
            {
                this.ViewState["StartTitle"] = value;
            }
        }

        [Category("Show Changer Appearance"), Description("changer type"), DefaultValue("ChangerType.Arrow"), Bindable(true)]
        public ChangerType Type
        {
            get
            {
                if (this.ViewState["ChangerType"] == null)
                {
                    this.ViewState["ChangerType"] = ChangerType.Arrow;
                }
                return (ChangerType) this.ViewState["ChangerType"];
            }
            set
            {
                this.ViewState["ChangerType"] = value;
            }
        }

        [Category("Show Changer Appearance"), Description("vertical aligning of the changer content"), DefaultValue("ChangerVerticalAlign.Middle"), Bindable(true)]
        public ChangerVerticalAlign VerticalAlign
        {
            get
            {
                if (this.ViewState["VerticalAlign"] == null)
                {
                    this.ViewState["VerticalAlign"] = ChangerVerticalAlign.Middle;
                }
                return (ChangerVerticalAlign) this.ViewState["VerticalAlign"];
            }
            set
            {
                this.ViewState["VerticalAlign"] = value;
            }
        }

        [Bindable(true), DefaultValue(50), Description("width of the show panels changer"), Category("Show appearance")]
        public int Width
        {
            get
            {
                if (this.ViewState["ChangerWidth"] == null)
                {
                    this.ViewState["ChangerWidth"] = 50;
                }
                return (int) this.ViewState["ChangerWidth"];
            }
            set
            {
                this.ViewState["ChangerWidth"] = value;
            }
        }
    }
}

